package com.example.clock.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.clock.entity.AttendHistory;
import com.example.clock.mapper.AttendHistoryMapper;
import com.example.clock.service.AttendHistoryService;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.time.LocalDate;
import java.time.LocalDateTime;

@Service
public class AttendHistoryServicesImpl extends ServiceImpl<AttendHistoryMapper, AttendHistory> implements AttendHistoryService {

    @Override
    public void saveHistory(String userName, LocalDate toLocalDate, LocalDateTime now, HttpServletRequest request) {
        String userAgent = request.getHeader("User-Agent");
        String osType = userAgent.substring(userAgent.indexOf("(") + 1, userAgent.indexOf(")"));
        String hostName = request.getRemoteHost();
        AttendHistory attendHistory = new AttendHistory(userName, now.toLocalDate(), now, osType, hostName);
        this.baseMapper.insert(attendHistory);
    }


}
